package com.kate.mall.product.service.impl;

import com.kate.mall.product.entity.GoodsEntity;
import com.kate.mall.product.service.GoodsService;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kate.mall.common.utils.PageUtils;
import com.kate.mall.common.utils.Query;

import com.kate.mall.product.dao.BrandDao;
import com.kate.mall.product.entity.BrandEntity;
import com.kate.mall.product.service.BrandService;

import javax.annotation.Resource;


@Service("brandService")
public class BrandServiceImpl extends ServiceImpl<BrandDao, BrandEntity> implements BrandService {

    @Resource
    private GoodsService goodsService;
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<BrandEntity> page = this.page(
                new Query<BrandEntity>().getPage(params),
                generatorWrapper(params)
        );

        return new PageUtils(page);
    }
    private  QueryWrapper<BrandEntity> generatorWrapper(Map<String, Object> params){
        QueryWrapper<BrandEntity> goodsEntityQueryWrapper = new QueryWrapper<>();
        if(params.containsKey("goods_id")){
            GoodsEntity goodsEntity = goodsService.getById(Integer.parseInt((String)params.get("goods_id")));
            if(goodsEntity==null){
                goodsEntity =new GoodsEntity();
                goodsEntity.setBrandId(-1);
            }
            goodsEntityQueryWrapper.lambda().eq(BrandEntity::getId,goodsEntity.getBrandId());
        }
        //TODO 要不要写逻辑删除条件？？？
        return goodsEntityQueryWrapper;
    }

}